package controller.cliente;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import to.Cliente;

public class ClienteDataModel extends ListDataModel<Cliente> implements SelectableDataModel<Cliente>, Serializable {    

	private static final long serialVersionUID = 4882200499686806604L;

	public ClienteDataModel() {  
    }  
  
    public ClienteDataModel(List<Cliente> data) {  
        super(data);  
    }  
      
    @Override  
    public Cliente getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
          
        List<Cliente> clis = (List<Cliente>) getWrappedData();  
          
        for(Cliente cli : clis) {  
        	String id = ""+cli.getId();
            if(id.equals(rowKey))  
                return cli;  
        }  
          
        return null;  
    }  
  
    @Override  
    public Object getRowKey(Cliente cli) {  
        return ""+cli.getId();  
    }  

}
